
package com.heimali.happyreader;

import android.app.Application;
import android.content.Context;
import android.widget.Toast;

import com.heimali.happyreader.core.bean.User;
import com.heimali.happyreader.utils.NetCheckUtils;

public class HappyReaderApplication extends Application {
    public static final String TAG = "HappyReaderApplication";
    public static long lastExitTime;
    public static boolean isNetworkAvailable = true;
    public static User curUserInfo;
    public static User loginUserInfo;
    public static User commonUserInfo;
    
    private static Application application = null;

    public void onCreate() {
        super.onCreate();
        application = this;
        commonUserInfo = new User("0", "heimali", "869a4b85");
        curUserInfo = commonUserInfo;
        loginUserInfo = new User().load();
        isNetworkAvailable = NetCheckUtils.isNetworkAvailable();
    }

    public static Application getApplication() {
        return application;
    }

    public static Context getContext() {
        return application.getBaseContext();
    }
    
    /**
    * 退出应用
    */
    public void exitApp() {
        long curTime = System.currentTimeMillis();
        if (curTime - lastExitTime > 2000) {
            lastExitTime = curTime;
            Toast.makeText(getContext(), R.string.back_confirm, Toast.LENGTH_SHORT).show();
            return;
        }

        System.exit(0);
    }
}
